package com.rt.gptnext.common.utils.http.validator;

import com.alibaba.fastjson2.JSONObject;
import com.rt.gptnext.common.utils.http.HttpResponse;
import com.rt.gptnext.common.utils.http.HttpSuccessValidator;

/**
 * @author gaoyiyang
 */
public interface JsonValidator extends HttpSuccessValidator {

    @Override
    default boolean valid(HttpResponse<byte[]> response) {
        byte[] raw = response.getRaw();
        if (raw[0] != '{' || raw[raw.length - 1] != '}') {
            return false;
        }
        return valid(response.getJsonObject());
    }

    boolean valid(JSONObject json);

}
